""""""

"""装饰带有参数的函数
def logging(fn):
    def inner(num1, num2):
        print("计算中....")
        fn(num1, num2)
    return inner

@logging
def sum_num(a, b):
    result = a + b
    print(result)

sum_num(2, 5)
"""

"""装饰带有返回值的函数
def logging(fn):
    def inner(num1, num2):
        print("计算中....")
        return fn(num1, num2)
    return inner

@logging
def sum_num(a, b):
    result = a + b
    return result

result = sum_num(2, 5)
print(result)
"""

"""带有不定长参数的函数
def logging(fn):
    def inner(*args, **kwargs):
        print("计算中。。。。")
        fn(*args, **kwargs)
    return inner

@logging
def sum_num(*args, **kwargs):
    result = 0
    for value in args:
        result += value

    for value in kwargs.values():
        result += value

    print(result)

sum_num(1, 2, a=10)
"""


"""通用装饰器"""
# 添加输出日志的功能
def logging(fn):
    def inner(*args, **kwargs):
        print("--正在努力计算--")
        result = fn(*args, **kwargs)
        return result

    return inner


# 使用语法糖装饰函数
@logging
def sum_num(*args, **kwargs):
    result = 0
    for value in args:
        result += value

    for value in kwargs.values():
        result += value

    return result


@logging
def subtraction(a, b):
    result = a - b
    print(result)

result = sum_num(1, 2, a=10)
print(result)

subtraction(4, 2)














